package com.atguigu.lease.common.exceptions;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(LeaseException.class)
    public Result leaseExceptionHandler(LeaseException e){
        e.printStackTrace();
        int code = e.getCode();
        String message = e.getMessage();
        return Result.build(message,code);
    }


    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        e.printStackTrace();
        Result<Object> fail = Result.fail();
        return fail;
    }


}
